# cython: language_level=3
from pydantic import BaseModel
from typing import Optional


class SendAgentMerchantsRequest(BaseModel):
    """
    {
        "systemTime":"2021-07-12 08:12:00",
        "creditCode":"91440300326639824D",
        "eventType":"agentMerchants"
    }
    """

    systemTime: str
    creditCode: str  # 负荷聚合商唯一标识
    eventType: str


class SendResourcesRequest(BaseModel):
    """
    {
        "systemTime":"2021-07-12 08:12:00",
        "creditCode":"91440300326639824D",
        "eventType":"resourceInfo"，
        "page":1，
        "pageSize":100
    }
    """

    systemTime: str
    creditCode: str  # 代理用户唯一标识
    eventType: str
    page: int
    pageSize: int


class SendRealTimeDataRequest(BaseModel):
    systemTime: str
    creditCode: str  # 负荷聚合商唯一标识
    eventType: str
    page: int
    pageSize: int


class ResourceInfo(BaseModel):
    """
    {
        "resourceId":"qianhai#01",
        "startTime":"2020-01-01 17:00:00",
        "endTime":"2020-01-01 18:00:00",
        "targetPower":200
    }
    """

    resourceId: str  # 唯一标识
    startTime: str  # 开始时间(yyyy-MM-dd HH:mm:00)
    endTime: str  # 结束时间(yyyy-MM-dd HH:mm:00)
    targetPower: int  # 功率目标值（kW）


class GetIntraDayTaskRequest(BaseModel):
    """
    虚拟电厂平台向负荷聚合平台下发日内紧急调控任务 请求参数
    {
        "taskCode":"RW20200101001",
        "creditCode":"91440300326639824D",
        "systemTime":"2021-07-1208:12:00",
        "taskName":"2020年1月1号削峰任务",
        "eventType":"intraDayTask",
        "page":1,
        "totalPage":1,
        "resourceList":[
            {
                "resourceId":"qianhai#01",
                "startTime":"2020-01-01 17:00:00",
                "endTime":"2020-01-01 18:00:00",
                "targetPower":200
            }
        ]
    }
    """

    taskCode: str  # 任务编号
    creditCode: str  # 负荷聚合商统一社会信用代码
    systemTime: str  # 系统时间戳，格式(yyyy-MM-dd HH:mm:ss)，
    taskName: str  # 任务名称
    eventType: str  # 事件类型，填：“intraDayTask”
    page: int  # 页码，默认为第一页
    totalPage: int  # 总页数，默认为1页
    resourceList: list[ResourceInfo]


class TimeSynRequest(BaseModel):
    """
    时间同步请求
    {
        "systemTime":"2021-07-12 08:12:00",
        "timescale":"1668664039000",
        "eventType":"timeSyn"
    }
    """

    systemTime: str
    timescale: str
    eventType: str


class GetInvitationRequest(BaseModel):
    """
    {
        "systemTime": "2021-07-12 08:12:00",
        "creditCode": "91440300552132052H",
        "eventType": "invitation",
        "invitationId": "20220225削峰计划",
        "invitationTime": "2022-02-24 16:30:00",
        "exchangeType": "RQXF",
        "page": 1,
        "totalPage": 1,
        "replyTime": "2022-02-24 19:30:00",
        "startTime": "2022-02-25 11:00:00",
        "endTime": "2022-02-25 11:30:00",
        "mrLine": {
                "00:15": -500,
                "00:30": -500
        },
        "inviteRange": "0945000048807386,0945000048815712",
        "baseLine": [
            {
                "resourceId": "0945000048807386",
                "00:15": 10.14,
                "00:30": 10.75
            },
            {
                "resourceId": "0945000048815712",
                "00:15": 10.14,
                "00:00": 10.75
            }
        ]
    }
    baseLine 中的 时间 是指的在此之前的 15分钟 平均功率值
    """

    systemTime: str
    creditCode: str
    eventType: str
    invitationId: str
    invitationTime: str
    exchangeType: str
    page: int
    totalPage: int
    replyTime: str
    startTime: str
    endTime: str
    mrLine: dict
    inviteRange: str
    baseLine: list[dict]


class SendReponsePlanRequest(BaseModel):
    """
    {
        "systemTime":"2021-07-12 08:12:00",
        "creditCode":"91440300326639824D",
        "invitationId":"20210105调峰计划",
        "page":1,
        "pageSize":100,
        "eventType":"responsePlan",
        "lastReplyTime":"2021-07-12 08:10:00"
    }
    """

    systemTime: str = None
    creditCode: str = None
    invitationId: str = None
    page: int = None
    pageSize: int = None
    eventType: str = None
    lastReplyTime: Optional[str] = None


class GetDayaheadPlanRequest(BaseModel):
    """
    {
        "systemTime":"2021-01-01 10:00:00",
        "planCode":"JH20210101001",
        "planName":"2021年1月1号计划",
        "planTime":"2021-01-01",
        "invitationId":"20220225调峰计划",
        "creditCode":"91440300326639824D",
        "eventType":"dayaheadPlan",
        "page":1,
        "totalPage":1,
        "vppPrices":{
            "00:15":100,
            "00:30":150
        },
        "vppPlans":{
            "00:15":100,
            "00:30":150
        },
        "responsePlan":[
            {
                "resourceId":"qianhai#01",
                "declare":{
                    "00:15":50,
                    "00:30":75
                }
            },
            {
                "resourceId":"qianhai#02",
                "declare":{
                    "00:15":50,
                    "00:30":75
                }
            }
        ]
    }
    """

    systemTime: str
    planCode: str
    planName: str
    planTime: str
    invitationId: str
    creditCode: str
    eventType: str
    page: int
    totalPage: int
    vppPrices: dict
    vppPlans: dict
    responsePlan: list[dict]


class GetResourceHistoryDataRequest(BaseModel):
    """
    {
        "systemTime":"2021-07-12 08:12:00",
        "resourceId":"JiankeFufure#01",
        "startTime":"2020-01-01 09:00:00",
        "endTime":"2020-01-30 09:00:00",
        "eventType":"historyData"
    }
    """

    systemTime: str
    resourceId: str
    startTime: str
    endTime: str
    eventType: str
